package cn.kgc.commons.exception;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>读取异常信息:exception-codes.properties</p>
 *
 * @author 王跃
 * @since 2022年09月24日 9:59
 */
@Data
@Component
@ConfigurationProperties(prefix = "exception")
@PropertySource(value =  "classpath:exception-codes.properties",encoding ="utf-8" )
public class ExceptionCodeConfig {
    private Map<Integer,String> codes=new HashMap<>();

    public  String getExceptionMessage(Integer exceptionCode){
            if(codes.containsKey(exceptionCode)){
                return codes.get(exceptionCode);
            }else{
                return "系统异常";
            }
    }
}